
Rem
	Convert a number between arbitrary bases
	Returns a String containing number represented in base tobase. The base in which
	number is given is specified in frombase. Both frombase And tobase have To be
	between 2 And 36, inclusive. Digits in numbers with a base higher than 10 will
	be represented with the letters a-z, with a meaning 10, b meaning 11 And z meaning 35. 
	
	@todo		Actually write it
	@author	Nicholas Grant
	@updatedby	
	@Return	String
EndRem
Function base_convert:String( number:String, frombase:Int, tobase:Int )
	If ( frombase > 1 And frombase < 37 And tobase > 1 And tobase < 37 )
		Local charlist$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		Local inputArray:Int[] = New Int[number.Length]
		Local outputList:TList = New TList
		Local givenLength% = 0	' Values are recalculated, this is to prevent that
		Local output$ = ""
		Local outVal% = 0
		Local calcVal% = 0
		Local calcMod% = 0
		Local baseMul% = 1
		Local cnt% = 0
		
		number = number.ToUpper()
		
		givenLength = number.Length - 1
		For cnt=0 To givenLength
			inputArray[cnt] = charlist.Find( number[cnt..cnt+1] )
		Next
		
		For cnt=inputArray.Length - 1 To 0 Step -1
			If ( cnt < inputArray.Length - 1 )
				baseMul :* frombase
			EndIf
			calcVal :+ inputArray[cnt] * baseMul
		Next
		
		While ( calcVal <> 0 )
			calcMod = calcVal Mod tobase
			outputList.AddFirst( String(calcMod) )
			calcVal :- calcMod
			calcVal :/ tobase
		Wend
		
		givenLength = outputList.Count() - 1
		For cnt=0 To givenLength
			outVal = Int( outputList.ValueAtIndex( cnt ).ToString() )
			output :+ charlist[outVal..outVal+1]
		Next
		
		Return output
	EndIf
	Return "";
End Function
